<?php slot("page", "setup"); ?>

<div class="row">
    
    <div class="span6">
    
        <?php if ($sf_user->hasFlash("passwordChangeAttempt") && $sf_user->getFlash("passwordChangeAttempt") && $sf_user->getFlash("errorField") == ""): ?>
            <div class="alert alert-success">Password change successful!</div>
        <?php elseif ($sf_user->hasFlash("passwordChangeAttempt") && $sf_user->getFlash("passwordChangeAttempt") && $sf_user->getFlash("errorField") == "other"): ?>
            <div class="alert alert-error"><?php echo $sf_user->getFlash("errorDescription") ?></div>
        <?php elseif ($sf_user->hasFlash("passwordChangeAttempt") && $sf_user->getFlash("passwordChangeAttempt") && $sf_user->getFlash("errorField") != "other"): ?>
            <div class="alert alert-error">Your password change could not be processed. Please correct the below errors and try again.</div>
        <?php endif; ?>
        
        <form id="change-password" class="form-horizontal well" action="<?php echo url_for("home/doPasswordChange") ?>" method="post">
            <fieldset>
                <legend>Change password</legend>
                
                <p>Passwords must be at least 8 characters long.</p>
                
                <div class="control-group" id="current-password-group">
                    <label class="control-label" for="current-password">Current password</label>
                    <div class="controls">
                        <input type="password" class="input-large" id="current-password" name="current-password" />
                    </div>
                </div>
                
                <div class="control-group" id="new-password-group">
                    <label class="control-label" for="new-password">New password</label>
                    <div class="controls">
                        <input type="password" class="input-large" id="new-password" name="new-password" />
                    </div>
                </div>
                
                <div class="control-group" id="confirm-new-password-group">
                    <label class="control-label" for="confirm-new-password">Confirm new password</label>
                    <div class="controls">
                        <input type="password" class="input-large" id="confirm-new-password" name="confirm-new-password" />
                    </div>
                </div>
                
                <div class="form-actions">
                    <button type="submit" class="btn btn-primary">Change</button>
                </div>
            </fieldset>
        </form>
        
        
        <?php if ($sf_user->hasFlash("emailSettingsChangeAttempt") && $sf_user->getFlash("emailSettingsChangeAttempt") && $sf_user->getFlash("errorDescription") == ""): ?>
            <div class="alert alert-success">Email settings change successful!</div>
        <?php elseif ($sf_user->hasFlash("emailSettingsChangeAttempt") && $sf_user->getFlash("emailSettingsChangeAttempt") && $sf_user->getFlash("errorDescription") != ""): ?>
            <div class="alert alert-error"><?php echo $sf_user->getFlash("errorDescription") ?></div>
        <?php endif; ?>
        
        <form id="change-email-settings" class="form-horizontal well" action="<?php echo url_for("home/doEmailSettingsChange") ?>" method="post">
            <fieldset>
                <legend>Change email settings</legend>
                
                <p><strong>Fydal</strong> can send you regular emails containing a summary of all new feedback, based on the frequency of your choice.</p>
                
                <p><strong>Important:</strong> these emails may be filtered by some email services' spam filters depending on the content of the user feedback summarised in
                    each email. Be sure to whitelist <em>noreply@fydal.com</em> to ensure this doesn't happen.</p>
                
                <div class="control-group" id="email-frequency-group">
                    <label class="control-label" for="email-frequency">Email frequency</label>
                    <div class="controls">
                        <select id="email-frequency" name="email-frequency">
                            <option value="never">Never</option>
                            <option value="daily" <?php if ($user->getNewFeedbackEmailType() == "daily") echo "selected"; ?>>Daily</option>
                            <option value="weekly" <?php if ($user->getNewFeedbackEmailType() == "weekly") echo "selected"; ?>>Weekly</option>
                        </select>
                    </div>
                </div>
                
                <div class="form-actions">
                    <button type="submit" class="btn btn-primary">Change</button>
                </div>
            </fieldset>
        </form>
        
        <script type="text/javascript">
            $(document).ready(function() {
                
                $("#change-password").submit(function() {
                    var isValid = false;
                    
                    $.formValidation.clearErrorFromField("current-password");
                    $.formValidation.clearErrorFromField("new-password");
                    $.formValidation.clearErrorFromField("confirm-new-password");
                    
                    if ($("#current-password").val()) {
                        if ($("#new-password").val()) {
                            if ($("#new-password").val().length >= 8) {
                                if ($("#new-password").val() == $("#confirm-new-password").val()) {
                                    isValid = true;
                                }
                                else {
                                    $.formValidation.addErrorForField("confirm-new-password", "Please ensure the new passwords match");
                                }
                            }
                            else {
                                $.formValidation.addErrorForField("new-password", "Please ensure passwords are at least 8 characters long");
                            }
                        }
                        else {
                            $.formValidation.addErrorForField("new-password", "Please enter a valid password");
                        }
                    }
                    else {
                        $.formValidation.addErrorForField("current-password", "Please enter the current password");
                    }
                    
                    return isValid;
                });
                
                <?php
                    if ($sf_user->hasFlash("passwordChangeAttempt") && $sf_user->getFlash("passwordChangeAttempt") && $sf_user->getFlash("errorField") != "" && $sf_user->getFlash("errorField") != "other") {
                        echo "$.formValidation.addErrorForField(\"" . $sf_user->getFlash("errorField") . "\", \"" . $sf_user->getFlash("errorDescription") . "\");";
                    }
                ?>
                
                <?php
                    if ($sf_user->hasFlash("passwordChangeAttempt") && $sf_user->getFlash("passwordChangeAttempt")) {
                        echo "$(window).scrollTop($('a#anchor-account').position().top);";
                    }
                ?>
            });
        </script>
        
    </div>
    
    <div class="span6">
        <div class="well">
            <fieldset>
                <legend>Change account type</legend>
                
                <?php
                    if ($user->isEligibleForUpgrade()) {
                        DisplayHelper::printUpgradeDetails();
                    }
                    else { ?>
                        <p>To downgrade your account back to a free account, simply click the PayPal unsubscribe.</p>
                        
                        <p style="text-align: center;">
                            <A HREF="https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=SG7KRXJLS3D7Q">
                                <IMG SRC="https://www.paypalobjects.com/en_AU/i/btn/btn_unsubscribe_LG.gif" BORDER="0" />
                            </A>
                        </p>
                <?php } ?>
            </fieldset>
        </div>
    </div>
    
</div>

